package com.mifengkong.cygtools.model;

import android.app.Activity;

import com.mifengkong.frtools.http.request.BaseRetrofit;
import com.mifengkong.frtools.http.request.callback.FRBaseObserver;
import com.mifengkong.frtools.util.FRDebugMode;
import com.mifengkong.frtools.util.FRLog;
import com.mifengkong.frtools.util.FRString;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.Observer;

/**
 * Created by jack on 2018/1/23
 */

public abstract class BaseModel extends BaseRetrofit {

    protected TestApi mServletApi;
    protected Map<String, Object> mParams = new HashMap<>();

    public BaseModel() {
        super();
        mServletApi = mRetrofit.create(TestApi.class);
    }

    @Override
    protected Map<String, String> getCommonMap() {
        Map<String, String> mCommonParams = new HashMap<>();
        mCommonParams.put("token","caf64c821ec48e2026c9bc42c9abed31");
        mCommonParams.put("user_id", "919119");
        mCommonParams.put("uid", "919119");
        return mCommonParams;
    }

    @Override
    protected Map<String, String> getHeaderParmasMap() {
        Map<String, String> mCommonParams = new HashMap<>();
        mCommonParams.put("version", "v2");
        return mCommonParams;
    }

    protected void addParamStrings(String key, Object value) {
        if (FRString.isEmpty(key)) {
            FRLog.error("key should not be null");
            return;
        }
        mParams.put(key, value);
    }

    protected void addParamStrings(Map<String, String> map) {
        if (null != map && map.size() > 0) {
            mParams.putAll(map);
        }
    }

    protected String getSecretKey() {
        return FRDebugMode.isDebugMode() ? "NnPZvNk7YH8#8tHSikz&!PJKCMGioTpY" : "WEkAoP*9a@3jqP$Cl#m9RW$p1reYV5CT";
    }

    @Override
    protected <T> void toSubscribe(Observable<T> observable, Observer<T> observer) {
        if (observer instanceof FRBaseObserver) {
            FRBaseObserver frBaseObserver = (FRBaseObserver) observer;
            Activity context = frBaseObserver.getContext();
            if (context != null) {
                frBaseObserver.setDefaultProgressDialogHandler(new APPProgressDialogHandler(context));
            }
        }
        super.toSubscribe(observable, observer);
    }
}
